package view.hero
{
import flash.display.MovieClip;

import framework.proxy.ComponentProxy;

import values.avatar.IAvatarValue;
import values.events.AvatarValueEvent;

/**
 * HeroSkillInfoProxy
 * @author jliang
 *
 */
public class HeroSkillInfoProxy extends ComponentProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function HeroSkillInfoProxy()
	{
		super();
	}
	//==========================================================================
	//  Properties
	//==========================================================================
	
	override public function dispose():void
	{
		_data = null;
		super.dispose();
	}
	
	private var _data:IAvatarValue;

	public function get data():IAvatarValue
	{
		return _data;
	}

	public function set data(value:IAvatarValue):void
	{
		if (data)
		{
			data.removeEventListener(AvatarValueEvent.SKILL_CHANGED, skillChangedHandler);
		}
		
		_data = value;
		
		normalSkill.data = data.selectedSkill;
		ultimateSkill.data = data.ultimateSkill;
		
		data.addEventListener(AvatarValueEvent.SKILL_CHANGED, skillChangedHandler);
	}
	
	public function get normalSkill():HeroSkillItemRenderProxy
	{
		return proxys["normalSkill"];
	}
	
	public function get ultimateSkill():HeroSkillItemRenderProxy
	{
		return proxys["ultimateSkill"];
	}
	//==========================================================================
	//  Overridden methods: RepeaterRenderProxy
	//==========================================================================	
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"normalSkill", classRef: HeroSkillItemRenderProxy, id:"normalSkill" },
			{ skin:"ultimateSkill", classRef: HeroSkillItemRenderProxy, id:"ultimateSkill" }
		];
	}
	
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
	}
	//==========================================================================
	//  Event handlers
	//==========================================================================
	protected function skillChangedHandler(event:AvatarValueEvent):void
	{
		if (data != event.params.avatar) return;
		
		normalSkill.data = data.selectedSkill;
	}
}
}